<?php
session_start();
$webroot="";
require_once 'header.php';
function __autoload($className)
	{
    	require_once('class/' . $className . '.class.php');
	}
session::need_seller();
if(session::is_manager()==TRUE)
{
	$agent=$agent=strval($_GET["agent"]);
}
else if(session::is_seller()==TRUE)
{
	$agentId=session::getuserid();
	$getAgent=database::LimitQuery("agent",array(
	'select' => 'agent_class',
	'condition' => array(
	'user_id' => $agentId
	)
	));
	if(!empty($getAgent))
	{
		$agent=$getAgent[0]['agent_class'];
	}
	
}

if(!empty($agent))
{
	$size="30";
	$page_id=0;
	if(!empty($_GET["pageid"]))
	{
		$page_id=intval($_GET["pageid"]);
		$num=intval($_GET["pageid"])-1;
		$offset=$num*$size;
	}
	else 
	{
		$offset=0;
	}
	$condition=array(
		'site' => $agent
		);
	$getPpOrderHistory=database::LimitQuery("orders",array(
		'condition' => $condition,
		'order' => 'order by id desc',
		'offset' => $offset,
		'size' => $size
		));
		
		$totalOrder=database::count("orders", $condition);
		$pages=ceil($totalOrder/$size);
	if(($pages>3)&&($page_id<$pages-3))
	{
		$pageMax=$pages-3;
	}
	else 
	{
		$pageMax=$pages;
	}
	
	if($page_id>=4)
	{
		$minPage=$page_id-3;
	}
	else 
	{
		$minPage=1;
	}
	if($page_id>=$pageMax-3)
	{
		$maxPage=$pageMax;
	}
	else 
	{
		$maxPage=$page_id+3;
	}
	if($page_id==$pages)
	{
		$nextPage=0;
	}
	else
	{
		$nextPage=$page_id+1;
	}
	if($page_id==1)
	{
		$previosPage=0;
	}
	else 
	{
		$previosPage=$page_id-1;
	}
	require_once 'html/sellerHistory.php';
}
else
{
	echo "no thing";
}

?>